function TreeNode(val){
    this.val = val;
    this.left = null;
    this.right = null;
}

const node =new TreeNode(1);   //{val:1,left:null,right:null}
const node1 =new TreeNode(2);   //{val:2,left:null,right:null}
const node2 =new TreeNode(3);   //{val:3,left:null,right:null}
node.left = node1;
node.right = node2;

obj ={
    val:1,
    left:{
        val:2,
        left:null,
        right:null
    },
    right:{
        val:3,
        left:null,
        right:null
    }
}
//先序遍历
function preorder(root){
    if(root ===null) return
    console.log(root.val)
    preorder(root.left)
    preorder(root.right)
}
preorder(obj)

//中序遍历
function inorder(root){
    if(root ===null) return
    inorder(root.left)
    console.log(root.val)
    inorder(root.right)
}
inorder(obj)

//后序遍历
function postorder(root){
    if(root ===null) return
    postorder(root.left)
    postorder(root.right)
    console.log(root.val)
}
postorder(obj)